package com.theme.common.base;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * @name: MoneyUnit <tb>
 * @title: 请输入类描述  <tb>
 * @author: cuixinfu@51play.com <tb>
 * @date: 2020/9/21 17:27 <tb>
 */
public class MoneyUtil {

    /**
     * 元转分，确保price保留两位有效数字
     *
     * @return
     */
    public static int changeY2F(double price) {
        DecimalFormat df = new DecimalFormat("#.00");
        price = Double.valueOf(df.format(price));
        int money = (int) (price * 100);
        return money;
    }

    /**
     * 分转元，转换为bigDecimal在toString
     *
     * @return
     */
    public static String changeF2Y(int price) {
        return BigDecimal.valueOf(Long.valueOf(price)).divide(new BigDecimal(100)).toString();
    }



    public static void main(String[] args) {
        System.out.println("WkaOrderController.main");
        System.out.println(changeF2Y(100010));
    }


}
